package org.jaaksi.kottlindemo.test

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updateLayoutParams
import androidx.core.widget.TextViewCompat
import extension.dp
import extension.resetAutoSize
import extension.resetAutoSize2
import extension.sp
import org.jaaksi.kottlindemo.databinding.ActivityTestAutosizeBinding
import org.jetbrains.anko.sp

class TestAutoSizeActivity : AppCompatActivity() {
    private val binding by lazy { ActivityTestAutosizeBinding.inflate(layoutInflater) }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(binding.root)

        binding.btnUpdate.setOnClickListener {
            binding.tvContent.text = "很长很长很长222"
            binding.tvContent.resetAutoSize(28.sp, maxHeightP = 20.dp)
        }
        binding.btnUpdate2.setOnClickListener {
            binding.tvContent.text = "很短很短"
            binding.tvContent.resetAutoSize(28.sp)
        }
        binding.btn.setOnClickListener {
            val maxSize = TextViewCompat.getAutoSizeMaxTextSize(binding.tvContent)
            println(">> textsize = ${binding.tvContent.textSize},maxSize = $maxSize")
        }
    }
}